package com.wedding.controller;

import com.wedding.service.UserService;
import org.apache.commons.fileupload.FileUploadException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
@RequestMapping("/other")
public class OtherController {

	@RequestMapping("/fileUpload2")
	public String fileUpload2(@RequestParam("jsonfile") MultipartFile file,
			HttpServletRequest request ) throws UnsupportedEncodingException, FileUploadException {
		System.out.println(file.getSize() +"=="+ file.getOriginalFilename());
		return "uploadsuccess";
	}
	@RequestMapping("/fileUpload3")
	public String fileUpload3(@RequestParam("upload") MultipartFile[] upload,
			HttpServletRequest request ) throws UnsupportedEncodingException, FileUploadException {
		if (upload!=null&&upload.length>0){
	        for (int i=0;i<upload.length;i++){
	            System.out.println(upload[i].getOriginalFilename());
//	            upload[i].transferTo(new File(file,filename));
	        }
	    }
		return "uploadsuccess";
	}

}
